package com.groupwork.meeting.controller;

import com.groupwork.meeting.entity.Role;
import com.groupwork.meeting.entity.User;
import com.groupwork.meeting.service.IRoleService;
import com.groupwork.meeting.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 鱼凫
 * @version 1.0
 * Create by 2021/11/2 10:37
 * @Description //TODO
 */

@RestController
@RequestMapping("role")
@ResponseBody
public class RoleController extends BaseController{
    @Autowired
    private IRoleService roleService;

    @GetMapping("get_by_uid")
    public JsonResult<Role> roleGetByUid(HttpSession session) {
        String uid = getUidFromSession(session);
        Role data = roleService.roleGetByUid(uid);
        return new JsonResult<Role>(OK,data);
    }

    @GetMapping("get_by_uname")
    public JsonResult<Role> roleGetByUname(HttpSession session) {
        String uname = getUidFromSession(session);
        Role data = roleService.roleGetByUid(uname);
        return new JsonResult<Role>(OK,data);
    }

    @RequestMapping("get_role_list")
    public JsonResult<List<Role>> getRoleList() {
        List<Role> data = roleService.getRoleList();
        return new JsonResult<>(OK,data);
    }

    @RequestMapping("{rname}/delete")
    public JsonResult<Void> delete(@PathVariable("rname") String rid){
        roleService.deleteRole(rid);
        return new JsonResult<Void>(OK);
    }

    @RequestMapping("addrole")
    public JsonResult<Void> addRole(Role role){
        roleService.addRole(role);
        return new JsonResult<Void>(OK);
    }
}
